package beans;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.beans.PropertyVetoException;
import java.beans.VetoableChangeListener;
import java.beans.VetoableChangeSupport;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;



public class Forum implements Serializable {

    private String titel;
    private String thema;
    private List<String> themen;
    private PropertyChangeSupport pcs;
    private VetoableChangeSupport vcs;
    
    
    public Forum() {
        titel   = "";
        thema   = "";
        themen  = new ArrayList<>();
        pcs     = new PropertyChangeSupport(this);
        vcs     = new VetoableChangeSupport(this);
    }

    
    public void setTitel(String title) {
        this.titel = title;
    }
    
        
    public String getTitel() {
        return this.titel;
    }
    
    
    public void setThema(String thema) throws PropertyVetoException {
        String oldThema = this.thema;
   
        try {   // Vetos einholen
            vcs.fireVetoableChange("Thema", oldThema, thema); 
            this.thema = thema;
            pcs.firePropertyChange("Thema", oldThema, this.thema);    
            this.themen.add(this.thema);
        } catch(PropertyVetoException pve) {
            throw pve;
        }
    }
    
    
    public void addVetoableChangeListener(VetoableChangeListener vcl) {
        vcs.addVetoableChangeListener(vcl);
    }
    
    
    public void removeVetoableChangeListener(VetoableChangeListener vcl) {
        vcs.removeVetoableChangeListener(vcl);
    }
    
    
    public void addPropertyChangeListener(PropertyChangeListener pcl) {
        pcs.addPropertyChangeListener(pcl);
    }
    
    
    public void removePropertyChangeListener(PropertyChangeListener pcl) {
        pcs.removePropertyChangeListener(pcl);
    } 
  
    
    public String getStatements() {
        String s = "verabschiedeten Absprachen im Forum '" + titel + "':\n";
        for(int i=0; i<themen.size(); i++) {
            s += ">> " + themen.get(i) + "\n";
        }
        return s;
    }
}
